package amqp.tutorials.tut5;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile({"tut5", "topics"})
@Configuration
public class Tut5Config {

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("tut.topic");
    }

    @Profile("receiver")
    public static class Re {


        @Bean
        public Tut5Receiver receiver() {
            return new Tut5Receiver();
        }


        @Bean
        public Queue autoDeleteQueue1() {
            AnonymousQueue anonymousQueue = new AnonymousQueue();
            System.out.println("1:" + anonymousQueue.hashCode());
            return anonymousQueue;
        }

        @Bean
        public Queue autoDeleteQueue2() {
            AnonymousQueue anonymousQueue = new AnonymousQueue();
            System.out.println("2:" + anonymousQueue.hashCode());
            return anonymousQueue;
        }


        @Bean
        public Binding binding1a(TopicExchange topic, Queue queue) {
            System.out.println("1-queue:" + queue.hashCode());
            return BindingBuilder.bind(queue).to(topic).with("*.orange.*");
        }

        @Bean
        public Binding binding1b(TopicExchange topic, Queue autoDeleteQueue1) {
            System.out.println("1-:" + autoDeleteQueue1.hashCode());

            return BindingBuilder.bind(autoDeleteQueue1).to(topic).with("*.*.rabbit");
        }

        @Bean
        public Binding binding2a(TopicExchange topic, Queue autoDeleteQueue2) {
            System.out.println("2-:" + autoDeleteQueue2.hashCode());
            return BindingBuilder.bind(autoDeleteQueue2).to(topic).with("lazy.#");
        }


    }

    @Profile("sender")
    @Bean
    public Tut5Sender sender() {
        return new Tut5Sender();
    }
}
